package analyticsServer;


import auctionServer.eventHierarcy.UserEvent;
import auctionServer.eventService.EventServer;
import auctionServer.eventService.OuterServer;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created with IntelliJ IDEA.
 * To change this template use File | Settings | File Templates.
 */
public class AnalyticsServer{

    public AnalyticsServer(String auctionServerAddress){
        //TODO importtaki OuterServer interfacedaki olmalı ama
        //TODO simdilik aynı projede calıstıgım için aynı yeri gösteriyor
        try {
            new EventManager();
        } catch (RemoteException e) {
            //TODO exception yönet
            e.printStackTrace();
        }

        createConnectionWithAuctionServer(auctionServerAddress);

    }

    protected AnalyticsServer() throws RemoteException {
        super();
    }

    private void createConnectionWithAuctionServer(String auctionServerAddress) {
        try {
            Registry registry = LocateRegistry.getRegistry("localhost", 20012);
            OuterServer obj = (OuterServer) registry.lookup("OuterServer");
            obj.connectAnalyticsServer("123");

        } catch (Exception e) {
            System.out.println("Client exception: " +
                    e.getMessage());
            e.printStackTrace();
        }
    }
}
